package com.jinzhi.jzweb.service.impl.modelConfig;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.jzweb.dao.modelConfig.DeclareReadyDao;
import com.jinzhi.jzweb.domain.modelConfig.DeclareReadyDO;
import com.jinzhi.jzweb.service.modelConfig.DeclareReadyService;
import com.jinzhi.sys.domain.UserDO;
import com.jinzhi.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.jinzhi.common.base.CoreServiceImpl;

import java.util.Date;

/**
 * 
 * <pre>
 * 申报材料表
 * </pre>
 * <small> 2024-01-10 09:31:39 | lance</small>
 */
@Service
public class DeclareReadyServiceImpl extends CoreServiceImpl<DeclareReadyDao, DeclareReadyDO> implements DeclareReadyService {

    @Autowired
    private UserService userService;

    @Override
    public Page<DeclareReadyDO> selectPage(DeclareReadyDO declareReadyDO, Page<DeclareReadyDO> page) {
        Wrapper<DeclareReadyDO> wrapper = new EntityWrapper<DeclareReadyDO>().orderBy("id", false);
        if (declareReadyDO.getTitle() != null) {
            wrapper.like("title", declareReadyDO.getTitle());
        }
//        wrapper.eq("is_deleted",0);
        return super.selectPage(page, wrapper);
    }

    @Override
    public boolean insertDeclareReady(DeclareReadyDO declareReadyDO) {
        declareReadyDO.setCreaterDate(new Date());
        declareReadyDO.setStatus(0);
        declareReadyDO.setIsDeleted(0);
        UserDO userDO = userService.getByUserId(declareReadyDO.getCreaterId());
        if(userDO!=null){
            declareReadyDO.setCreater(userDO.getName());
        }
        return super.insert(declareReadyDO);
    }

    @Override
    public boolean updateDeclareReadyById(DeclareReadyDO declareReadyDO) {
        declareReadyDO.setUpdateDate(new Date());
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq("id",declareReadyDO.getId());
        return super.update(declareReadyDO,wrapper);
    }

    @Override
    public boolean deleteDeclareReadyById(Long id) {
        DeclareReadyDO declareReadyDO = new DeclareReadyDO();
        declareReadyDO.setIsDeleted(1);
        declareReadyDO.setUpdateDate(new Date());
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq("id",id);
        return super.update(declareReadyDO,wrapper);
    }
}
